package Test;

import entity.Cat;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class CatTest {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException {
        Class<Cat> clz =Cat.class;
        Cat cat = clz.newInstance();

        Field name = clz.getDeclaredField("catName");
        name.setAccessible(true);
        name.set(cat, "小毛");



        Field age = clz.getDeclaredField("age");
        age.setAccessible(true);
        age.set(cat, 22);

        Method show = clz.getDeclaredMethod("show",int.class,String.class);
        show.setAccessible(true);
        Object res = show.invoke(cat, age.get(cat), name.get(cat));
        System.out.println(res);
        //System.out.println(show.invoke(cat));
    }
}
